package cmj.cloudmusic.activity.receiverActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import cmj.cloudmusic.R;
import cmj.cloudmusic.receiver.MyFirstReceiver;

public class ReceiverActivity extends AppCompatActivity {
    MyFirstReceiver receiver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        if (receiver==null){
//            receiver=new MyFirstReceiver();
//            IntentFilter filter=new IntentFilter();
//            filter.addAction("android.intent.action.FIRST_DEMO");
//            registerReceiver(receiver,filter);
//        }

        setContentView(R.layout.activity_receiver);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent("android.intent.action.FIRST_DEMO");
                intent.putExtra("msg","HKJHKKHJKHJKHKHJK");
//                sendBroadcast(intent);//普通
//                sendOrderedBroadcast(intent,null);//有序
                sendBroadcast(intent,"android.permission.TEST_BROADCAST");
            }
        });
    }

    @Override
    protected void onDestroy() {
        if (receiver!=null){
            unregisterReceiver(receiver);
        }
        super.onDestroy();
    }
}
